/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vn.ac.c0910g.assignment.DAO;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import vn.ac.c0910g.assignment.Entity.Payment;
import vn.ac.c0910g.assignment.Entity.PaymentFacade;

/**
 *
 * @author BachLe
 */
public class PaymentDAO {
    PaymentFacade paymentFacade = lookupPaymentFacadeBean();

    public PaymentDAO(){

    }
    private PaymentFacade lookupPaymentFacadeBean() {
        try {
            Context c = new InitialContext();
            return (PaymentFacade) c.lookup("java:global/Alluring_Decors/Alluring_Decors-ejb/PaymentFacade!vn.ac.c0910g.assignment.Entity.PaymentFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public List<Payment> getAllPayment(){
        return this.paymentFacade.findAll();
    }

    public void addPayment(Payment p){
        paymentFacade.create(p);
    }

    public void updatePayment(Payment p){
        paymentFacade.edit(p);
    }

    public void deletePayment(Payment p){
        paymentFacade.remove(p);
    }

    public Payment findPaymentById(String Id){
        return paymentFacade.find(Id);
    }
}
